package org.hank.wanandroid.ui.fragment

import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.android.synthetic.main.fragment_square_tree.*
import org.hank.commom.base.BaseFragment
import org.hank.commom.listener.ReloadListener
import org.hank.wanandroid.R
import org.hank.wanandroid.adapter.SquareAdapter
import org.hank.wanandroid.bean.ProjectBean
import org.hank.wanandroid.viewmodel.SquareTreeViewModel

//  ┏┓　　　┏┓
//┏┛┻━━━┛┻┓
//┃　　　　　　　┃
//┃　　　━　　　┃
//┃　┳┛　┗┳　┃
//┃　　　　　　　┃
//┃　　　┻　　　┃
//┃　　　　　　　┃
//┗━┓　　　┏━┛
//    ┃　　　┃                  神兽保佑
//    ┃　　　┃                  永无BUG！
//    ┃　　　┗━━━┓
//    ┃　　　　　　　┣┓
//    ┃　　　　　　　┏┛
//    ┗┓┓┏━┳┓┏┛
//      ┃┫┫　┃┫┫
//      ┗┻┛　┗┻┛
/**
 *@auth: Hank
 *邮箱: cs16xiaoc1@163.com
 *创建时间: 2021/5/27 17:14
 *描述:
 */
class SquareTreeFragment : BaseFragment(R.layout.fragment_square_tree), ReloadListener {
    var projectBeanList: MutableList<ProjectBean> = ArrayList()
    var treeAdapter = SquareAdapter<ProjectBean>(projectBeanList)

    val viewModel by getViewModel(SquareTreeViewModel::class.java) {
        treeLiveData.observe(it) {
            loadingTip.dismiss()
            projectBeanList.addAll(it)
            treeAdapter.notifyDataSetChanged()
        }
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        recycler_fragment_square_tree.apply {
            layoutManager = LinearLayoutManager(context)
            adapter = treeAdapter
        }
        viewModel.getTreeList()
        loadingTip.loading()
        loadingTip.setReloadListener(this)
    }

    override fun showToast(msg: String) {
        super.showToast(msg)
        loadingTip.showInternetError()
    }

    override fun reload() {
        loadingTip.loading()
        viewModel.getTreeList()
    }
}